package com.xiaoniucr.util;

import org.springframework.util.DigestUtils;

/**
 * @author Mr.Yang
 * @create 2020/10/23 22:21
 * @copyright www.xiaoniucr.com
 */
public class PwdEncryUtil {

    public static void main(String[] args) {

        String password = "123456";
        System.out.println("原始密码===>"+password);
        String salt = "cfdd7312-2fb1-4e6a-a657-597328d7627a";
        String getMd5Password = getMd5Password(password,salt);
        System.out.println("加密密码===>"+getMd5Password);

    }


    /**
     * 获取执行MD5加密后的密码
     * @param password
     * @param salt
     * @return	返回加密后的密码
     */
    private static String getMd5Password(String password,String salt) {
        //加密规则---自行加密---使用(“盐+密码+盐”)作为原始数据,执行5次进行加密
        String result = salt+password+salt;
        for (int i = 0; i < 5; i++) {
            result = DigestUtils.md5DigestAsHex( result.getBytes() ).toUpperCase();
        }
        return result;
    }
}
